package com.thread.join.demo1;

public class Joiner extends Thread {

	private Sleeper sleeper;

	public Joiner(String name, Sleeper sleeper) {
		super(name);
		this.sleeper = sleeper;
		start();
	}

	public void run() {
		try {
			// 作用是让两个线程同步。例如：有A,B两个线程，如果在B中调用了A.join()的话，则表示A线程执行完了才开始执行B线程。
			sleeper.join();
		} catch (InterruptedException e) {
			System.out.println("Interrupted");
			return;
		}
		System.out.println(getName() + " join completed");
	}

}
